package cn.dw.web.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;

import cn.dw.domain.People;
import cn.dw.domain.User;
import cn.dw.service.Userservice;

public class UserAction
  extends ActionSupport
  implements ModelDriven<People>
{
  private static final long serialVersionUID = -2944680680387766747L;
  private User user = new User();
  private People people = new People();
  private Userservice us;
  
  @InputConfig(resultName="login")
  public String login()
    throws Exception
  {
    try
    {
      User u = this.us.login(this.user);
      ActionContext.getContext().getSession().put("user", u);
      return "toHome";
    }
    catch (Exception e)
    {
      e.printStackTrace();
      addActionError(e.getMessage());
    }
    return "login";
  }
  
  public People getModel()
  {
    return this.people;
  }
  
  public void setUs(Userservice us)
  {
    this.us = us;
  }
}
